﻿using System.Web;
using System.Web.SessionState;
using MugenInjection.Scope;
using MugenInjection.Syntax.Method;
using MugenInjection.Syntax.Type;

// ReSharper disable CheckNamespace

namespace MugenInjection
// ReSharper restore CheckNamespace
{
    /// <summary>
    /// Scope syntax extension.
    /// </summary>
    public static class ScopeSyntaxEx
    {
        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP request, for scope used <see cref="HttpContext"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static IMethodCallbackObjectPriorityUseWithSyntax InHttpRequestScope(this IMethodScopeSyntax scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.HttpRequestScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP request, for scope used <see cref="HttpContext"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static ITypeCallbackConstructorObjectPriorityUseWithSyntax InHttpRequestScope(
            this ITypeScopeSyntax scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.HttpRequestScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP session, for scope used <see cref="HttpSessionState"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static IMethodCallbackObjectPriorityUseWithSyntax InSessionScope(this IMethodScopeSyntax scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.SessionScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP session, for scope used <see cref="HttpSessionState"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static ITypeCallbackConstructorObjectPriorityUseWithSyntax InSessionScope(
            this ITypeScopeSyntax scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.SessionScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// OperationContext request, for scope used OperationContext.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static IMethodCallbackObjectPriorityUseWithSyntax InOperationRequestScope(
            this IMethodScopeSyntax scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.OperationRequestScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// OperationContext request, for scope used OperationContext.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static ITypeCallbackConstructorObjectPriorityUseWithSyntax InOperationRequestScope(
            this ITypeScopeSyntax scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.OperationRequestScopeProvider));
        }

        //-----------

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP request, for scope used <see cref="HttpContext"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static IMethodCallbackObjectPriorityUseWithSyntax<T> InHttpRequestScope<T>(this IMethodScopeSyntax<T> scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.HttpRequestScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP request, for scope used <see cref="HttpContext"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static ITypeCallbackConstructorObjectPriorityUseWithSyntax<T> InHttpRequestScope<T>(
            this ITypeScopeSyntax<T> scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.HttpRequestScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP session, for scope used <see cref="HttpSessionState"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static IMethodCallbackObjectPriorityUseWithSyntax<T> InSessionScope<T>(this IMethodScopeSyntax<T> scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.SessionScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// HTTP session, for scope used <see cref="HttpSessionState"/>.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static ITypeCallbackConstructorObjectPriorityUseWithSyntax<T> InSessionScope<T>(
            this ITypeScopeSyntax<T> scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.SessionScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// OperationContext request, for scope used OperationContext.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static IMethodCallbackObjectPriorityUseWithSyntax<T> InOperationRequestScope<T>(
            this IMethodScopeSyntax<T> scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.OperationRequestScopeProvider));
        }

        /// <summary>
        /// Indicates that instances activated via the binding should be re-used within the same
        /// OperationContext request, for scope used OperationContext.
        /// </summary>
        /// <param name="scopeSyntax"></param>
        /// <returns>The fluent syntax.</returns>
        public static ITypeCallbackConstructorObjectPriorityUseWithSyntax<T> InOperationRequestScope<T>(this ITypeScopeSyntax<T> scopeSyntax)
        {
            return scopeSyntax.InScope(new WebContextScopeLifecycle(WebContextScopeLifecycle.OperationRequestScopeProvider));
        }
    }
}